import { defineStore } from 'pinia'
import { ref } from 'vue'

const initState = {
  cinemaName: '',
  currentCity: '',
  settlementInfo: {},
  // 本地存储时间
  localStorageTime: 0,
}

export const useCinemaStore = defineStore(
  'cinema',
  () => {
    const cinemaInfo = ref<ICinemaInfo>({ ...initState })
    const setCinemaInfo = (val: ICinemaInfo) => {
      cinemaInfo.value = val
    }
    const clearCinemaInfo = () => {
      cinemaInfo.value = { ...initState }
    }
    const editCinemaInfo = (options) => {
      cinemaInfo.value = { ...cinemaInfo.value, ...options }
    }
    return {
      cinemaInfo,
      setCinemaInfo,
      clearCinemaInfo,
      editCinemaInfo,
    }
  },
  {
    // 如果需要持久化就写 true, 不需要持久化就写 false（或者去掉这个配置项）
    persist: true,
  },
)
